<?php $rack_form = $this->beginWidget('CActiveForm', array(
		'id'=>'rack-form',
		'enableClientValidation'=>true,
	//	'enableAjaxValidation'=>true,
		));
?>

<div class="racklist">

<?php

	$states = Racks::model()->getAllStates();
	$count = 0;
	$addspace = true;
	
	foreach ($states as $record) {
		$count++;
		$state = $record->state;
		$racks = Racks::model()->getRacks($state);
		
		// need to work on overflow...
		if ($count == 1)
			echo '<div class="rack-col">' . "\n";
		else if ($count % 65 == 0) {
			echo '</div>' . "\n";
			echo '<div class="rack-col">' . "\n";
			
		}			
			
		echo '<h2>' . $state . '</h2>' . "\n";
		
		foreach ($racks as $record) {
			$count++;
			$rack = $record->city;
			$rackID = $record->rack_ID;
			
			$checked = '';
			
			if (OrgRackRelation::model()->hasRack(Yii::app()->user->userID, $rackID))
				$checked = 'checked';				
					
			echo '<div class="rack"><input name="racks[]" type="checkbox" value="'.$rack.'"' . $checked . '/>' . $rack . '</div>' . "\n";
			
			if ($count % 65 == 0) {
				echo '</div>' . "\n";
				echo '<div class="rack-col">' . "\n";
				$addspace = false;
			}
		}
		
		if ($addspace)
			echo '<br />';
		else
			$addspace = true;
	}
?>
</div><!-- End last rack column -->
</div><!--  End rack list -->

<div id="rack-submit">
<?php echo CHtml::imageButton(Yii::app()->request->baseUrl.'/images/submit.jpg', array(
									'ajax'=>array(				
										'type'=>'POST',
										'url'=>CController::createUrl('admin/racks'),
										'success'=>'updateStatus',
										'dataType'=>'json',
									),
								)
							); ?>
</div>

<?php $this->endWidget();?>